home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / PowerPlant / PP Balloon Help Support / CBalloonApp.cp next >
Encoding:
Text File  |  1996-08-06  |  3.5 KB  |  129 lines  |  [TEXT/CWIE]

  1. // Source for CBalloonApp class
  2.  
  3.  
  4. #include "CBalloonApp.h"
  5. #include "CHelpAttach.h"
  6.  
  7. #include <LListIterator.h>
  8. #include <LWindow.h>
  9. #include <UDrawingState.h>
  10.  
  11. // ===========================================================================
  12. //        • CBalloonApp Class
  13. // ===========================================================================
  14.  
  15. // ---------------------------------------------------------------------------
  16. //        • CBalloonApp
  17. // ---------------------------------------------------------------------------
  18. //    Constructor
  19.  
  20. CBalloonApp::CBalloonApp()
  21. {
  22. }
  23.  
  24.  
  25. // ---------------------------------------------------------------------------
  26. //        • ~CBalloonApp
  27. // ---------------------------------------------------------------------------
  28. //    Destructor
  29.  
  30. CBalloonApp::~CBalloonApp()
  31. {
  32. }
  33.  
  34. // Handle cursor motion for help balloons
  35. void CBalloonApp::AdjustCursor(const EventRecord    &inMacEvent)
  36. {
  37.                                     // Find out where the mouse is
  38.     WindowPtr    macWindowP;
  39.     Point        globalMouse = inMacEvent.where;
  40.     Int16        thePart = ::FindWindow(globalMouse, &macWindowP);
  41.     
  42.     Boolean        useArrow = true;    // Assume cursor will be the Arrow
  43.     
  44.     if (macWindowP != nil) {        // Mouse is inside a Window
  45.  
  46.         LWindow    *theWindow = LWindow::FetchWindowObject(macWindowP);
  47.         if ((theWindow != nil) &&
  48.             theWindow->IsActive() &&
  49.             theWindow->IsEnabled()) {
  50.                                     // Mouse is inside an active and enabled
  51.                                     //   PowerPlant Window. Let the Window
  52.                                     //   adjust the cursor shape.
  53.                                     
  54.                                     // Get mouse location in Port coords
  55.             Point    portMouse = globalMouse;
  56.             theWindow->GlobalToPortPoint(portMouse);
  57.             
  58.             theWindow->AdjustCursor(portMouse, inMacEvent);
  59.             useArrow = false;
  60.  
  61. // ----------------
  62. // Start of my bit
  63. // ----------------            
  64.             // Find the top pane under the mouse
  65.             LPane* hitPane = GetPaneUnderMouse(theWindow, portMouse.h, portMouse.v);
  66.  
  67.             // Execute the CHelpAttach if the pane exists
  68.             if (hitPane)
  69.                 hitPane->ExecuteAttachments(msg_ShowHelp, (void*) hitPane);
  70. // ----------------
  71. // End of my bit
  72. // ----------------            
  73.         }
  74.     }
  75.     
  76.     if (useArrow) {                    // Window didn't set the cursor
  77.                                     // Default cursor is the arrow            
  78.         SetCursor(&UQDGlobals::GetQDGlobals()->arrow);
  79.     }    
  80.     
  81.         // Rather than trying to calculate an accurate mouse region,
  82.         // we define a region that contains just the one pixel where
  83.         // the mouse is located. This is quick, and handles the common
  84.         // case where this application is in the foreground but the user
  85.         // isn't doing anything. However, any mouse movement will generate
  86.         // a mouse-moved event.
  87.         
  88.     ::SetRectRgn(mMouseRgnH, globalMouse.h, globalMouse.v,
  89.                              globalMouse.h + 1, globalMouse.v + 1);
  90. }
  91.  
  92. // Find the pane currently under the mouse
  93. LPane* CBalloonApp::GetPaneUnderMouse(
  94.     LPane*        inPane,
  95.     Int32        inHorizPort,
  96.     Int32        inVertPort)
  97. {
  98. #if 0
  99.     LPane    *hitSubPane = nil;
  100.  
  101.     // Does this pane provide a hit?
  102.     if (!inPane->FindShallowSubPaneContaining(inHorizPort, inVertPort))
  103.     
  104.         // No hit => return this pane
  105.         return inPane;
  106.  
  107.     // If there was a hit then we know that inPane is in fact a LView so
  108.     // we can cast to get subpane list
  109.     
  110.     // Loop over all subpanes to find the first visible pane hit
  111.     LListIterator iterator(((LView*) inPane)->GetSubPanes(), iterate_FromEnd);
  112.     LPane    *theSub;
  113.     
  114.     while (iterator.Previous(&theSub)) {
  115.         if (theSub->Contains(inHorizPort, inVertPort) && theSub->IsVisible()) {
  116.             hitSubPane = GetPaneUnderMouse(theSub, inHorizPort, inVertPort);
  117.             if (hitSubPane == nil) {
  118.                 hitSubPane = theSub;
  119.             }
  120.             break;
  121.         }
  122.     }
  123.     
  124.     return hitSubPane;
  125. #else
  126.     return inPane->FindDeepSubPaneContaining(inHorizPort, inVertPort);
  127. #endif
  128. }
  129.